Skip to content

Fix time-related unit tests on alpine linux#4069

Merged
clumens merged 4 commits intoClusterLabs:mainfrom
clumens:strftime
Mar 16, 2026
Merged

Fix time-related unit tests on alpine linux#4069
clumens merged 4 commits intoClusterLabs:mainfrom
clumens:strftime

Conversation

@clumens
Copy link
Contributor

@clumens clumens commented Mar 11, 2026

@nrwahl2 This came up in CI testing yesterday. @fabbione is probably going to want this in sooner rather than later, and I'm off the rest of this week. Feel free to modify this as appropriate and push. I have tested this on both Fedora and Alpine, but not FreeBSD (which is relevant). Luckily, most or all of this is going to go away when we can get rid of the strftime fallback, whenever that is.

Not all platforms support this because it's a glibc extension.  For
instance, musl on Alpine Linux doesn't support it.
@clumens clumens requested a review from nrwahl2 March 11, 2026 13:15
[AC_DEFINE([HAVE_STRFTIME_WIDTH], [1],
[Define to 1 if strftime supports field width])])

AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good lord this is ugly. I looked around a bit for a cleaner way, but this seems like about the best we can do, other than potentially dropping bare declarations:

char s[200] = { '\0', };
time_t t = time(NULL);

return strftime(s, sizeof(s), "% abcd", localtime(&t)) != 0;

With that said, we use HAVE_STRFTIME_EMPTY_SPEC_FAILS only in one unit test file. So alternatively, we could add a setup function there that tests whether strftime() returns nonzero when there's an empty spec, and sets a file-scope variable if so.

I don't have strong feelings on it and it's not worth spending a ton of time on. Hopefully this all goes away in the future.

clumens added 3 commits March 16, 2026 09:29
Alpine uses musl by default, which doesn't include a lot of the glibc
extensions including the field width specifier for strftime().
Unfortunately, it doesn't support it in a completely different way from
FreeBSD (and maybe other BSDs, but we don't support those).  So, we need
to handle each case differently in our tests.
On some platforms, like musl on Alpine Linux, the bare percent sign is
an error and the results will be an empty string.  Add a test for this.
Alpine uses musl by default, which handles bare percent signs in
strftime() differently.  On that platform, a bare percent sign (or an
unknown specifier) results in an empty string.  We need to check for
that and handle it in our test cases.
@clumens clumens merged commit 593eba4 into ClusterLabs:main Mar 16, 2026
1 check passed
@clumens clumens deleted the strftime branch March 16, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants